package swidgets;


import processing.core.*;
import controlP5.*;

public class SWDisplayWords {
	private ControlTimer ct;
	private Textlabel tx;
	PFont fnt;
	long tick_size;
	
	private String[] words = { "one", "two", "three", "four" };
	int wc;
	
	public SWDisplayWords (final ControlP5 theControlP5, final PApplet thePApplet) {
		init (theControlP5, thePApplet);
	}	
	
	private void init (final ControlP5 theControlP5, final PApplet thePApplet) {
		fnt = thePApplet.loadFont("CourierNewPS-BoldMT-24.vlw");
		tx = new Textlabel(theControlP5,"--",200,200);
		tx.setFont(fnt);
		ct = new ControlTimer ();
		ct.setSpeedOfTime(1);
		wc = words.length;
		tick_size = 1000;
	}
	
	
	public SWDisplayWords setTempo(float qnpm, float notesz) {
		double sz;
		sz = 60.0 * 1000.0 / qnpm * notesz;
		
		tick_size = (long) sz;
		return this;		
	}
	
	public SWDisplayWords setPosition(float theX, float theY){
		tx.setPosition(theX, theY);
		return this;
	}
	
	public void render () {
		int secs;
		long millisecs;
		
		millisecs = ct.time();
		secs = (int) (millisecs / tick_size);
		tx.setValue( words[secs % wc] );
		tx.draw();
	}
	
}
